#!/bin/sh

os=$(uname -s)

if [[ "$os" == "Darwin" ]]; then
	host_tag="darwin-x86_64"
elif [[ "$os" == "CYGWIN"* ]]; then
	host_tag="windows-x86_64"
else
	host_tag="linux-x86_64"
fi

PROJECT=runner
PROFILE=dev
PROFILE_DIR=debug

TARGET_DIR=../
RUNNER_DIR=./

if [[ "$1" = "ios" ]]; then
	TARGET=aarch64-apple-ios
	cargo build --target $TARGET --profile $PROFILE -p $PROJECT --example ios
fi

if [[ "$1" = "mac" ]]; then
	TARGET=aarch64-apple-darwin
	cargo build --target $TARGET --profile $PROFILE -p $PROJECT --example mac
	RUST_BACKTRACE=1 $TARGET_DIR/target/$TARGET/$PROFILE_DIR/examples/mac
fi

if [[ "$1" = "wine" ]]; then
	TARGET=x86_64-pc-windows-gnu
	cargo build --target $TARGET --profile $PROFILE -p $PROJECT --example win
	wine $TARGET_DIR/target/$TARGET/$PROFILE_DIR/examples/win.exe
fi

if [[ "$1" = "ndk" ]]; then
	TARGET=aarch64-linux-android
	cargo build --profile $PROFILE --target $TARGET -p $PROJECT --example ndk

	cp	$TARGET_DIR/target/$TARGET/$PROFILE_DIR/examples/libndk.so \
	$RUNNER_DIR/android/app/src/main/jniLibs/arm64-v8a/libxloop.so
fi

if [[ "$1" = "linux" ]]; then
	TARGET=aarch64-unknown-linux-gnu
	cargo build --profile $PROFILE --target $TARGET -p $PROJECT --example linux
fi
